package org.idea.spring.ioc;

import org.idea.spring.ioc.repository.PersonRepository;
import org.springframework.beans.PropertyEditorRegistrySupport;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 关于ioc的依赖注入案例
 *
 * @Author idea
 * @Date created in 9:25 上午 2020/5/1
 */
public class IocDependencyInjectionDemo {

    public static void main(String[] args) {
        //此时已经有两个Spring的上下文personRepository
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("META-INF/bean-dependency-injection");
        PersonRepository personRepository = (PersonRepository) applicationContext.getBean("personRepository");
        whoIsIocContainerCore(applicationContext);
        //会读取多个person对象
        System.out.println(personRepository.getPersons());
        System.out.println(personRepository.getBeanFactory());
        System.out.println(personRepository.getObjectFactory().getObject());
        // 判断容器内部上下文注入的beanFactory是否是beanFactory 输出内容为false
        System.out.println(personRepository.getBeanFactory() == applicationContext);
        ApplicationEvent applicationEvent;
    }

    /**
     * 谁才是ioc容器的真正底层
     */
    private static void whoIsIocContainerCore(ApplicationContext applicationContext){
        System.out.println(applicationContext);
    }
}
